package uz.rt.linac;

/**
 * .
 * User: Wacko von Belsebub
 * Date: 10/30/11
 * Time: 7:48 PM
 */
public class Leaf extends LinacComponent
{
    private double lowerLimit = 0.0;
    private double upperLimit = 0.0;
    private double value = (lowerLimit + upperLimit) / 2;
    private double thickness = 0.0;
    private double speed = 0.0;

    public Leaf(final double value)
    {
        this.value = value;
    }

    public Leaf(final double value, final double lowerLimit, final double upperLimit)
    {
        this.value = value;
        this.lowerLimit = lowerLimit;
        this.upperLimit = upperLimit;
    }

    public boolean isValid()
    {
        return value < lowerLimit || value > upperLimit || lowerLimit > upperLimit;
    }

    public double getLowerLimit()
    {
        return lowerLimit;
    }

    public void setLowerLimit(double lowerLimit)
    {
        this.lowerLimit = lowerLimit;
    }

    public double getUpperLimit()
    {
        return upperLimit;
    }

    public void setUpperLimit(double upperLimit)
    {
        this.upperLimit = upperLimit;
    }

    public double getValue()
    {
        return value;
    }

    public void setValue(double value)
    {
        this.value = value;
    }

    public double getThickness()
    {
        return thickness;
    }

    public void setThickness(double thickness)
    {
        this.thickness = thickness;
    }

    public double getSpeed()
    {
        return speed;
    }

    public void setSpeed(double speed)
    {
        this.speed = speed;
    }

    @Override
    public boolean equals(Object o)
    {
        if (this == o) return true;
        if (!(o instanceof Leaf)) return false;

        Leaf leaf = (Leaf) o;

        return Double.compare(leaf.lowerLimit, lowerLimit) == 0 && Double.compare(leaf.speed, speed) == 0 && Double
                .compare(leaf.thickness, thickness) == 0 && Double.compare(leaf.upperLimit, upperLimit) == 0 && Double
                .compare(leaf.value, value) == 0;

    }

    @Override
    public int hashCode()
    {
        int result;
        long temp;
        temp = lowerLimit != +0.0d ? Double.doubleToLongBits(lowerLimit) : 0L;
        result = (int) (temp ^ (temp >>> 32));
        temp = upperLimit != +0.0d ? Double.doubleToLongBits(upperLimit) : 0L;
        result = 31 * result + (int) (temp ^ (temp >>> 32));
        temp = value != +0.0d ? Double.doubleToLongBits(value) : 0L;
        result = 31 * result + (int) (temp ^ (temp >>> 32));
        temp = thickness != +0.0d ? Double.doubleToLongBits(thickness) : 0L;
        result = 31 * result + (int) (temp ^ (temp >>> 32));
        temp = speed != +0.0d ? Double.doubleToLongBits(speed) : 0L;
        result = 31 * result + (int) (temp ^ (temp >>> 32));
        return result;
    }
}
